import menuApi from '@/views/api/system/menu/menu'

const state = {
    asyncRoutes: []
}

const mutations = {
    SET_ASYNC_ROUTES: (state, routes) => {
        state.asyncRoutes = routes
    }
}

const actions = {
    getRoute({ dispatch, commit }, userType) {
        return new Promise((resolve, reject) => {
            menuApi.getRouteList(userType).then(response => {
                const { data } = response
                commit('SET_ASYNC_ROUTES', data)
                resolve()
            })
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
